package com.maddox.relax.dialog;


import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;

import com.maddox.relax.R;


public class LoadindDialog extends AlertDialog {

    private TextView textView;
    private String message;
    private static LoadindDialog loadindDialog ;
    public static void initLoadindDialog(Context context){

        loadindDialog =  new LoadindDialog(context);
        loadindDialog.show();
    }

    public LoadindDialog(@NonNull Context context, @NonNull String message) {
        this(context, R.style.LoadingDialogStyle);
        this.message= message;
    }
    public LoadindDialog(@NonNull Context context) {
        this(context, R.style.LoadingDialogStyle);
        this.message= "正在加载中...";
    }
    protected LoadindDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_loading_view);
        textView = findViewById(R.id.progressMsg);
        setCancelable(true);
        setCanceledOnTouchOutside(false);
        setMessage(message);
    }



    private void setMessage(String message) {
        textView.setText(message);
    }

    public static void dismss(){
        if(loadindDialog!=null && loadindDialog.isShowing()){
            loadindDialog.dismiss();
            loadindDialog = null ;
        }
    }
}
